<script setup lang="ts">
  import { ref, defineEmits, watch, onMounted, PropType } from 'vue';
  import { useBooleanStore } from '@/store';
  import { searchCarTask } from '@/api/les';
  import { LocationTypeOption } from '@/api/les/types';

  const props = defineProps({
    typeOptions: Array as PropType<LocationTypeOption[]>,
  });

  const emit = defineEmits(['updateArray']);
  const booleanStore = useBooleanStore();
  // 表单查询数据
  const type = ref('');

  const pageSize = ref(10);
  const pageNumber = ref(1);

  // 表格数据
  async function handleSearch() {
    const newData = await searchCarTask({
      carTaskType: type.value,
      current: pageNumber.value,
      size: pageSize.value,
    });
    emit('updateArray', newData);
  }
  // 重置
  function reset() {
    type.value = '';

    handleSearch();
  }
  onMounted(() => {
    handleSearch();
  });
  // 监听分页
  watch([() => booleanStore.pageNum, () => booleanStore.pageSize], () => {
    if (booleanStore.num5 === 70) {
      pageNumber.value = booleanStore.pageNum;
      pageSize.value = booleanStore.pageSize;
      handleSearch();
    }
  });
  watch(
    () => booleanStore.update,
    () => {
      if (booleanStore.num6 === 30) handleSearch();
    }
  );
</script>

<template>
  <a-row :gutter="{ md: 8, lg: 24, xl: 32 }">
    <a-col :span="6">
      <div>
        <a-select
          v-model="type"
          placeholder="任务类型"
          size="large"
          allow-clear
          :options="typeOptions"
        />
      </div>
    </a-col>
    <a-col :span="6">
      <a-button type="primary" size="large" @click="handleSearch"
        >查询</a-button
      >
      <a-button class="btn-reset" size="large" @click="reset">重置</a-button>
      <!-- <a-button type="primary" class="btn-reset" size="large">分配班组</a-button> -->
      <!-- <a-button type="primary" class="btn-reset" size="large">下发计划</a-button> -->
    </a-col>
  </a-row>
</template>

<style scoped>
  .btn-group {
    float: right;
    margin-top: 15px;
  }

  .btn-reset {
    margin-left: 10px;
  }
</style>
